---
title: "Validation Paper: How terrorist attacks distort public debates: A comparative study of right-wing and Islamist extremism"
date: "`r Sys.Date()`"
author: "Teresa Völker^[WZB Berlin Social Science Center, teresa.voelker@wzb.eu]"
abstract: \singlespacing The success of extremist actors depends on their visibility, resonance, and legitimacy in public debates. Previous research has shown how terrorist attacks attract media attention and influence public opinion and decision-makers. However, we lack a comparative assessment of the extent to which extremist ideologies matter and how they matter. Therefore, this paper compares mass media debates over extreme right and Islamist terrorist attacks. Theoretically, it innovates by linking research on discursive critical junctures and issue-specific discursive opportunity structures, emphasizing the systematic differences between the two ideologies. Empirically, the study is based on an original, large-scale content analysis of mass media debates on all seven fatal attacks in Germany since 2015 (N=9,047). It combines relational quantitative content analysis with frame and network analyses. The results show how the ideology behind terrorist attack shape political response and the framing of the key security threat. Notably, both types of attacks provide favourable conditions for the far right, and political elites play a central role in the diffusion of far-right frames. In contrast, victims and ethnic or religious minorities have little voice in public debates. Overall, the study contributes to a better understanding of the impact of terrorist attacks on Western democracies by emphasizing the impact of ideology and distorted threat perceptions in public debates.
Keywords: far right; terrorism; public debates; right-wing extremism; Islamist extremism; public opinion
output: 
    html_document:
        toc: true
        code_folding: hide
---

# Description

This R script includes the code for the validation the analysis of the paper "How terrorist attacks distort public debates: A comparative study of right-wing and Islamist extremism". It uses the Terrorism Debate Data (TDD). In this test, I reran the central analyses to control for the severity of the attack (number of casualties). Therefore, I exclude the two events with the highest number of casualties, namely the Islamist attack in Berlin and the right-wing attack in Hanau.The dataset includes the mass media debate after the Islamist attacks in Hamburg and Dresden and after the right-wing attacks in Munich, Halle and against Lübcke.The dataset includes core-sentence analysis data of SZ & Welt.




```{r setup, include=FALSE}

knitr::opts_chunk$set(echo = TRUE, 
                      message =FALSE, 
                      warning =FALSE
                     )

#change echo=FALSE to hide code for pdf
###load packages

library(plyr)
library(tidyverse)
library(lubridate)
library(writexl)
library(reshape2)
library(kableExtra)
library(ghibli)
library(viridisLite)
library(viridis)
library(readtext)
library(tidyr)
library(dplyr)
library(stringi)
library(stringr)
library(readr)
library(ggrepel)


#renv::activate

```






```{r load clean data}

# load Terrorist Debate Dataset (TDD)

load("TDD_short.RData")

#rename dataset to all

all <- TDD_short



```



```{r create id for issue_groups}


all <- all%>% 
  dplyr::mutate(subissue_group_id = case_when(subissue_group_eng == "antisemitism"  ~ 1650,
     subissue_group_eng == "asylum"  ~ 1050,                 
     subissue_group_eng == "immigration"  ~ 800,          
      subissue_group_eng == "integration"  ~ 900,          
      subissue_group_eng == "Islam rights"  ~ 600,    
     subissue_group_eng == "Islam symbols"  ~ 400,    
     subissue_group_eng == "Islamist extremism"  ~ 1780,          
     subissue_group_eng == "islamophobia"  ~ 1800,     
     subissue_group_eng == "multiculturalism"  ~ 1100,   
     subissue_group_eng == "national identity"  ~ 1300, 
     subissue_group_eng == "nativism"  ~ 1400,                 
      subissue_group_eng == "racism"  ~ 1200,           
       subissue_group_eng == "radicalisation"  ~ 1820,                 
       subissue_group_eng == "refugees" ~ 1000,
       subissue_group_eng == "right-wing extremism"  ~ 1700,    
  subissue_group_eng == "security politics"  ~ 1900,      
   subissue_group_eng ==    "tradition"  ~ 1500,   
                 TRUE ~ NA_real_))
                

```



## Annex C. Validation Results

**exclude the two events with the highest number of casualties, namely the Islamist attack in Berlin and the right-wing attack in Hanau**


```{r variable case ideology period}

# Islamist attacks  Hamburg Anschlag 28.7.2017 Dresden 04/10/2020
#exclude: Berlin 19/12/2016
#Right-wing attacks München 22/07/2016;  Halle 09/10/2019 Lübcke Murder 02/06/2019
#exclude: Hanau 19/02/2020

#create variables for cases: one week before and two weeks after attacks

all <- all %>% 
  mutate(case = case_when(date > "2016-07-14" & date < "2016-08-06" ~ "Munich '16",
                          #date > "2016-12-11" & date < "2017-01-04" ~ "Berlin '16", 
                          date > "2017-07-20" & date < "2017-08-12" ~ "Hamburg '17",
                          date > "2019-05-24" & date < "2019-06-17" ~ "Luebcke '19", 
                          date > "2019-10-01" & date <"2019-10-24" ~ "Halle '19",
                          #date > "2020-02-11" & date <"2020-03-05" ~ "Hanau '20",
                          date > "2020-09-27" & date < "2020-10-19" ~ "Dresden '20",
                          TRUE ~ "other"))


# create variable by ideology - exclude big cases to validate analyses (Berlin 2016 & Hanau 2020)
all <- all %>% 
  mutate(ideology = case_when(date > "2016-07-14" & date < "2016-08-06" ~ "right",
                        #  date > "2016-12-11" & date < "2017-01-04" ~ "is", 
                          date > "2017-07-20" & date < "2017-08-12" ~ "is",
                          date > "2019-05-25" & date < "2019-06-17" ~ "right", 
                          date > "2019-10-01" & date <"2019-10-24" ~ "right",
                         # date > "2020-02-11" & date <"2020-03-05" ~ "right",
                          date > "2020-09-27" & date < "2020-10-19" ~ "is",
                          TRUE ~ "other"))


# create variable for period 
all <- all %>% 
  mutate(period = case_when((date > "2016-07-14" & date < "2016-07-23") & case == "Munich '16" ~ "before",
                            (date > "2016-07-22" & date < "2016-07-31") & case == "Munich '16" ~ "week1",
                            (date > "2017-07-20" & date < "2017-07-29") & case == "Hamburg '17" ~ "before",
                            (date > "2017-07-28" & date < "2017-08-06") & case == "Hamburg '17" ~ "week1",
                            (date > "2020-09-27" & date < "2020-10-05") & case == "Dresden '20" ~ "before",
                            (date > "2020-10-04" & date < "2020-10-13") & case == "Dresden '20" ~ "week1",
                            (date > "2019-05-24" & date < "2019-06-03") & case == "Luebcke '19" ~ "before",
                            (date > "2019-06-02" & date < "2019-06-11") & case == "Luebcke '19" ~ "week1",
                            (date > "2019-10-01" & date < "2019-10-10") & case == "Halle '19" ~ "before",
                            (date > "2019-10-10" & date < "2019-10-18") & case == "Halle '19" ~ "week1",
                          #  (date > "2020-02-11" & date < "2020-02-20") & case == "Hanau '20" ~ "before",
                           # (date > "2020-02-19" & date < "2020-02-28") & case == "Hanau '20" ~ "week1",
                           # (date > "2016-12-11" & date < "2016-12-20") & case == "Berlin '16" ~ "before",
                           # (date > "2016-12-19" & date < "2016-12-27") & case == "Berlin '16" ~ "week1",
                            TRUE & case != "other" ~ "week2"))



```



## Divide cases right-wing & Islamist attacks


```{r split cases}



# Islamist attacks

 
#Berlin 19/12/2016: 12.12.-2.1.2017

#berlin <- all %>% filter(date > "2016-12-19" & date < "2017-01-04")

#berlin_before <- all %>% filter(date > "2016-12-11" & date < "2016-12-20")

#berlin1week <- all %>% filter(date > "2016-12-19" & date < "2016-12-27")

#Hamburg Anschlag 28.7.2017: 21.7-11.8.17

hamburg <- all %>% filter(date > "2017-07-28" & date < "2017-08-12")

hamburg_before <- all %>% filter(date > "2017-07-20" & date < "2017-07-29")

hamburg_1week <- all %>% filter(date > "2017-07-28" & date < "2017-08-06")

#Dresden 04/10/2020

dresden <- all%>% filter(date > "2020-10-04" & date < "2020-10-19")

dresden_before <- all %>% filter(date > "2020-09-27" & date < "2020-10-05")

dresden_week1 <- all%>% filter(date > "2020-10-04" & date < "2020-10-13")


## right attacks

# München 22/07/2016: 15.7.- 5.8.2016
munich<- all %>% filter(date > "2016-07-22" & date < "2016-08-06")

munich_before <-all %>% filter(date > "2016-07-14" & date < "2016-07-23")

munich_week1 <- all %>% filter(date > "2016-07-22" & date < "2016-07-31")


# Lübcke 02/06/2019: 26.5.19- 25.6 (coded till 29.6. to include delayed debate) 

lubcke <- all%>% filter(date > "2019-06-02" & date < "2019-06-17")

lubcke_before <- all %>% filter(date > "2019-05-24" & date < "2019-06-03")

lubcke_1week <- all%>% filter(date > "2019-06-02" & date < "2019-06-11")

## Halle 09/10/2019: 02.10.-23.10.2020  

halle <- all%>% filter(date > "2019-10-09" & date < "2019-10-24")

halle_before <- all %>% filter(date > "2019-10-01" & date < "2019-10-10")

halle_week1 <- all%>% filter(date > "2019-10-09" & date < "2019-10-18")

# Hanau 19/02/2020: 12.2.-4.3.21

#hanau <- all %>% filter(date > "2020-02-19" & date < "2020-03-05")

#hanau_before <- all%>% filter(date > "2020-02-11" & date < "2020-02-20")

#hanau_week1 <- all %>% filter(date > "2020-02-19" & date < "2020-02-28")



# Christchurch 15/03/2019 : 08.03.- 29.03.2019

christ_before <- all %>% filter(date > "2019-03-07" & date < "2019-03-16")

christ <- all %>% filter(date > "2019-03-15" & date < "2019-03-30")

christ_1week <- all %>% filter(date > "2019-03-15" & date < "2019-03-24")

#Buffalo 13.05.2022:	5.5.-27.5 

buffalo<- all %>% filter(date > "2022-05-13" & date < "2022-05-28")


#Oslo 25.6.22: 18.6.-9.7

oslo<- all %>% filter(date > "2022-06-25" & date < "2022-09-08")


```




```{r merge cases}


#Islamist attacks
# Hamburg 2017,Dresden 04/10/2020 ; EXCLUDE Berlin 2016,

is_before <- bind_rows (dresden_before, hamburg_before)

is <- bind_rows(hamburg,dresden)

is_week1 <- bind_rows (dresden_week1, hamburg_1week)


## Merge right attacks 2016-2020 ; EXCLUDE HANAU

right_before <- bind_rows(munich_before,halle_before,lubcke_before)

# right = all newspaper articles after right attacks
right <- bind_rows (halle,lubcke, munich)

#  right_1week = one week after all right attacks

right_1week <- bind_rows(halle_week1,lubcke_1week,munich_week1)

# before & after all national attacks 

all_before <- bind_rows(right_before ,is_before)

all_after <- bind_rows(right,is)

all_1week <- bind_rows (right_1week,is_week1)



## international cases

#Islamist attacks:Paris 16/10/2020, Nizza 29/10/2020,  Wien 02/11/2020

internation_is <- all %>% filter(date > "2020-10-16" & date < "2020-11-17")


# Right attacks: Christchurch 2019, Oslo, Buffalo 2022

international_right <- bind_rows (christ, oslo, buffalo)


# international all

all_internation <- bind_rows (international_right,internation_is)


# all right (national & international)

right_all <- bind_rows (right, international_right)

# all islamist (national & international)


is_all <- bind_rows (is,internation_is)




```




# Results


# Visibility  



**Prepare data for actor analyses**


```{r actor type distribution right is}

## merge subject & object

#select variables 
actor_type_r <- select(right,c("subject1_eng", "object1_eng"))  

## make dateset longer
actor_type_r <-pivot_longer(actor_type_r, cols = c("subject1_eng", "object1_eng"))


#rename value variable 
actor_type_r <- dplyr::rename(actor_type_r,actor=value)

#remove missings
actor_type_r<- actor_type_r %>%
  filter(!is.na(actor))


## is
#merge subject & object

#select variables 
actor_type_i <- select(is,c("subject1_eng", "object1_eng"))  

## make dateset longer
actor_type_i <-pivot_longer(actor_type_i, cols = c("subject1_eng", "object1_eng"))


#rename value variable 
actor_type_i <- dplyr::rename(actor_type_i,actor=value)

#remove missings
actor_type_i<- actor_type_i %>%
  filter(!is.na(actor))


#count actor types is & right

actor_type_r_count <- actor_type_r%>% 
   filter(!is.na(actor)) %>%
  group_by(actor)%>% 
  mutate(count_right=1) %>% 
  dplyr::summarise(count_right = sum(count_right))%>% 
  mutate (pct_right_attacks=count_right/sum(count_right)*100)%>% 
  arrange(desc(count_right))

actor_type_i_count <- actor_type_i %>% 
   filter(!is.na(actor)) %>%
  group_by(actor)%>% 
  mutate(count_islamist=1) %>% 
  dplyr::summarise(count_islamist = sum(count_islamist))%>% 
  mutate (pct_islamist_attacks=count_islamist/sum(count_islamist)*100)%>% 
  arrange(desc(count_islamist))
  
##top actors is & right
actor_type_r_top<- top_n(actor_type_r_count,14)

actor_type_i_top <- top_n(actor_type_i_count,14)

```



```{r count subject and object is right}


actor_subject <- all_after%>% 
  group_by(subject1_eng)%>% 
   filter(!is.na(subject1_eng)) %>% 
  mutate(count=1) %>% 
  dplyr::summarise(count = sum(count))%>% 
  mutate (pct=round((count/sum(count)*100),2)) %>% 
arrange(desc(count))

actor_subject_i <- is%>% 
  group_by(subject1_eng)%>% 
   filter(!is.na(subject1_eng)) %>% 
  mutate(count=1) %>% 
  dplyr::summarise(count_is = sum(count))%>% 
  mutate (pct_islamist_attacks=round((count_is/sum(count_is)*100),2)) %>% 
arrange(desc(count_is))

actor_subject_r <- right%>% 
  group_by(subject1_eng)%>% 
   filter(!is.na(subject1_eng)) %>% 
  mutate(count=1) %>% 
  dplyr::summarise(count_right = sum(count))%>% 
  mutate (pct_right_attacks=round((count_right/sum(count_right)*100),2)) %>% 
arrange(desc(count_right))

#export excel

#write_xlsx(actor_subject_r, "actor_subject_r.xlsx")
#write_xlsx(actor_subject_i, "actor_subject_i.xlsx")

#all
actor_object <- all_after%>% 
  group_by(object1_eng)%>% 
   filter(!is.na(object1_eng)) %>% 
  mutate(count=1) %>% 
  dplyr::summarise(count = sum(count))%>% 
  mutate (pct=round((count/sum(count)*100),2)) %>% 
arrange(desc(count))

#right
actor_object_r <- right %>% 
  group_by(object1_eng)%>% 
   filter(!is.na(object1_eng)) %>% 
  mutate(count=1) %>% 
  dplyr::summarise(count_right = sum(count))%>% 
  mutate (pct_right_attacks=round((count_right/sum(count_right)*100),2)) %>% 
arrange(desc(count_right))


#is
actor_object_i <- is%>% 
  group_by(object1_eng)%>% 
   filter(!is.na(object1_eng)) %>% 
  mutate(count=1) %>% 
  dplyr::summarise(count_is = sum(count))%>% 
  mutate (pct_islamist_attacks=round((count_is/sum(count_is)*100),2)) %>% 
arrange(desc(count_is))

#export excel
#write_xlsx(actor_object_i, "actor_object_i.xlsx")
#write_xlsx(actor_object_r, "actor_object_r.xlsx")

```


## Appendix: Figure B2. Resonance actor types after Islamist and right-wing attacks


```{r merge visualize all subjects is and right}

#merge subjects after is and right attacks for overview & visualization
   
actor_subject_isright <- left_join(actor_subject_i, actor_subject_r , by="subject1_eng")


#write_xlsx(actor_subject_isright, "actor_subject_isright.xlsx")


#use merged data

## make dateset longer
actor_type_all2  <-pivot_longer(actor_subject_isright, cols = c("pct_right_attacks", "pct_islamist_attacks"))

#rename 
actor_type_all2 <-dplyr::rename(actor_type_all2 ,ideology_attack=name)



#visualize subject actors islamist & right-wing
# stack=on top of each other ; dodge =next to each other
# scale y-lab:  ylim(0,100)+

plot_subjectsall<- ggplot(actor_type_all2, aes(x=reorder(subject1_eng, -value), y=value, fill=ideology_attack)) + 
  geom_bar(stat = 'identity', position = 'dodge') +
  ylab("share sentences in %") + 
  xlab("Actor types") +
theme_light()+
   theme(axis.text.x = element_text(angle=65, hjust=1))+
  scale_fill_manual(values = c("pct_right_attacks" = "#33CCCC", "pct_islamist_attacks" = "#FF9999"),
                    labels = c("pct_right_attacks" = "extreme right attack", "pct_islamist_attacks" = "Islamist attack"))  # Mapping of values to labels

# Rename the variable in the legend
plot_subjectsall<- plot_subjectsall + labs(fill = "ideology")


plot_subjectsall

#ggsave(filename="B2.Resonance_actor_types.jpeg", plot=plot_subjectsall, device="jpeg", units="cm", width=20, height=13, dpi=300)


```




### Figure C1: Validation results: Public visibility of extremists versus victims

```{r visibility extremists vs victims}

# filter victims and extremists as subject actor

subject_vic<- actor_subject_isright %>%   
  mutate(actor = case_when(   
                    subject1_eng== "extreme right actors" ~ "Right-wing extremists",
    subject1_eng== "Islamist actors" ~ "Islamist extremists",
    subject1_eng== "ethnic minority groups" ~ "ethnic/religious minorities",
      subject1_eng== "victims" ~ "victims general",
 subject1_eng== "scientists and experts" ~ "other",
                              subject1_eng== "individuals" ~ "other",
                           subject1_eng== "supranational organisations" ~ "other",
                            subject1_eng== "left groups" ~ "other",
                       subject1_eng== "sport and cultural organisations" ~ "other",
                    subject1_eng== "muslim actors" ~ "Muslim actors",
                 subject1_eng== "ethnic minority groups" ~ "other minorities",
            subject1_eng== "Jewish actors" ~ "Jewish actors", ))


#filter Nas and other actors
subject_vic <-  subject_vic%>% filter(!is.na(actor))  


subject_vic <-  subject_vic%>% filter(!actor=="other") 


#subject_central <- subject_central %>% filter(!(actor=="other"))


## make dateset longer
actor_type_all4  <-pivot_longer(subject_vic , cols = c("pct_right_attacks", "pct_islamist_attacks"))

#rename 
actor_type_all4 <-dplyr::rename(actor_type_all4 ,ideology_attack=name)



#plat subject actors islamist & right-wing
# stack=on top of each other ; dodge =next to each other
# scale y-lab:  ylim(0,100)+

plot_subjects4 <- ggplot(actor_type_all4, aes(x = reorder(actor, -value), y = value, fill = ideology_attack)) + 
  geom_bar(stat = 'identity', position = 'dodge') +
  ylab("share sentences in %") + 
  xlab("Actor types") +
  theme_light() +
  theme(axis.text.x = element_text(angle = 65, hjust = 1)) +
  scale_fill_manual(values = c("pct_right_attacks" = "#33CCCC", "pct_islamist_attacks" = "#FF9999"),
                    labels = c("pct_right_attacks" = "extreme right attack", "pct_islamist_attacks" = "Islamist attack"))  # Mapping of values to labels

# Rename the variable in the legend
plot_subjects4 <- plot_subjects4 + labs(fill = "ideology")

plot_subjects4


#ggsave(filename="FigureC1.Validation results_victims.jpeg", plot=last_plot(), device="jpeg", units="cm", width=20, height=13, dpi=300)




```






```{r names extremists versus victims}

# calculate total & share names; after right attack = N= 2808, after islamist attacks=N=1638

names_victims_right <- right%>% 
     filter(subject1_eng=="victims")%>%
  group_by(subject3_string)%>% 
  mutate(count=1) %>% 
  dplyr::summarise(count = sum(count))%>% 
  mutate(victim_right=count/2808*100)%>% 
arrange(desc(count))

names_victims_is <- is%>% 
     filter(subject1_eng=="victims")%>%
  group_by(subject3_string)%>% 
  mutate(count=1) %>% 
  dplyr::summarise(count = sum(count))%>% 
  mutate(victim_is=count/1638*100)%>% 
arrange(desc(count))

names_extremist_right <- right%>% 
     filter(subject1_eng=="extreme right actors")%>%
  group_by(subject3_string)%>% 
  mutate(count=1) %>% 
  dplyr::summarise(count = sum(count))%>% 
  mutate(ex_right=count/2808*100)%>% 
arrange(desc(count))

names_extremist_is <- is %>% 
     filter(subject1_eng=="Islamist actors")%>%
  group_by(subject3_string)%>% 
  mutate(count=1) %>% 
  dplyr::summarise(count = sum(count))%>% 
  mutate(ex_is=count/1638*100)%>% 
arrange(desc(count))

names_1 <- full_join(names_extremist_is, names_extremist_right,by="subject3_string")

names_2 <- full_join(names_victims_is, names_victims_right, by="subject3_string")


names_extremist_victims <- full_join(names_1,names_2, by="subject3_string")

names_extremist_victims <- names_extremist_victims %>% select(-count.x.x,-count.y.y, -count.y.x,-count.x.y)  %>%  filter(!is.na(subject3_string))


#export victim & extremist share of names 
#write_xlsx(names_extremist_victims, "names_extremist_victims.xlsx")


```







```{r visualize all objects is and right}

#merge subjects after is and right attacks for overview & visualization
actor_object_isright <- left_join(actor_object_i, actor_object_r , by="object1_eng")


#write_xlsx(actor_object_isright, "actor_object_isright.xlsx")

# summarize actor types - other & ethnic/religious minorities (including victims)
#subsume police under executive |actor== "police and security authorities"

#use merged data

## make dataset longer
actor_type_all4  <-pivot_longer(actor_object_isright, cols = c("pct_right_attacks", "pct_islamist_attacks"))

#rename 
actor_type_all4 <-dplyr::rename(actor_type_all4 ,ideology_attack=name)



#visualize subject actors Islamist & right-wing
# stack=on top of each other ; dodge =next to each other
# scale y-lab:  ylim(0,100)+

plot_objectsall<- ggplot(actor_type_all4, aes(x=reorder(object1_eng, -value), y=value, fill=ideology_attack)) + 
  geom_bar(stat = 'identity', position = 'dodge', alpha = 0.6) +
  ylab("share sentences in %") + 
  xlab("Actor types") +
  theme_minimal() + 
   theme(axis.text.x = element_text(angle=65, hjust=1))+
  ggtitle("Resonance objects in the context of terrorist attacks")

plot_objectsall


```





# Resonance 


### Table C2: Validation results: Resonance: share of political parties as subject and object in political debates after terrorist attacks, percentages 

**Part 1: share of political parties as subject in political debates after terrorist attacks, percentages**

```{r party distribution as subjects after attacks}



#create table
parties_right <- right%>% 
  group_by(subject_2_string) %>% 
   filter(!is.na(subject_2_string)) %>% 
  filter(subject_2_string=="CDU" | subject_2_string=="AfD" |subject_2_string=="SPD" | subject_2_string=="FDP" | subject_2_string=="Die Linke" |subject_2_string=="CSU" | subject_2_string=="Bündnis 90/Die Grünen")%>% 
  mutate(count=1) %>% 
  dplyr::summarise(count = sum(count))%>% 
  mutate (pct_right=round((count/sum(count)*100),2)) %>% 
arrange(desc(count)) 



# party distribution after is attacks
parties_is <- is%>% 
  group_by(subject_2_string) %>% 
   filter(!is.na(subject_2_string)) %>% 
  filter(subject_2_string=="CDU" | subject_2_string=="AfD" |subject_2_string=="SPD" | subject_2_string=="FDP" | subject_2_string=="Die Linke" |subject_2_string=="CSU" | subject_2_string=="Bündnis 90/Die Grünen")%>% 
  mutate(count=1) %>% 
  dplyr::summarise(count = sum(count))%>% 
  mutate (pct_is=round((count/sum(count)*100),2)) %>% 
arrange(desc(count))

# merge for export

parties_as_subjects <- left_join(parties_right,parties_is, by="subject_2_string")

#write_xlsx(parties_as_subjects, "parties_as_subjects.xlsx")

parties_as_subjects




```


**Part 2: share of political parties as subject in political debates after terrorist attacks, percentages**

```{r party distribution as objects after attacks}



#create table

parties_right_o <- right%>% 
  group_by(object_2_string) %>% 
   filter(!is.na(object_2_string)) %>% 
  filter(object_2_string=="CDU" | object_2_string=="AfD" |object_2_string=="SPD" |object_2_string=="FDP" | object_2_string=="Die Linke" |object_2_string=="CSU" | object_2_string=="Bündnis 90/Die Grünen")%>% 
  mutate(count=1) %>% 
  dplyr::summarise(count = sum(count))%>% 
  mutate (pct_right=round((count/sum(count)*100),2)) %>% 
arrange(desc(count)) 

# party distribution after is attacks
parties_is_o <- is%>% 
  group_by(object_2_string) %>% 
   filter(!is.na(object_2_string)) %>% 
  filter(object_2_string=="CDU" |object_2_string=="AfD" |object_2_string=="SPD" | object_2_string=="FDP" | object_2_string=="Die Linke" |object_2_string=="CSU" | object_2_string=="Bündnis 90/Die Grünen")%>% 
  mutate(count=1) %>% 
  dplyr::summarise(count = sum(count))%>% 
  mutate (pct_is=round((count/sum(count)*100),2)) %>% 
arrange(desc(count))

parties_as_objects <- left_join(parties_right_o,parties_is_o, by="object_2_string")

#export
#write_xlsx(parties_as_objects, "parties_as_objects.xlsx")

parties_as_objects


```






# Resonance Issues


## Figure C2.  Validation results: Resonance of central sub-issues, share of statements


```{r issue groups is and right}


#count issues, group by ideology, filter top issues
subissue_comp <- all_after%>% 
  dplyr::filter(!is.na(subissue_group_eng))%>% 
  mutate(count = 1) %>% 
  group_by(ideology,subissue_group_eng) %>% 
  dplyr::summarise(count_issue = sum(count))%>%
  mutate (pct=count_issue/sum(count_issue)*100)%>%
   top_n(13) %>%
arrange(desc(count_issue))

#plot

plot_subissue_comp<- ggplot(subissue_comp, aes(x=reorder(subissue_group_eng, -pct), y=pct, fill=ideology)) + 
  geom_bar(stat = 'identity', position = 'dodge') +
  ylab("share sentences in %") + 
  xlab("Sub-Issues") +
    theme_light()+
   theme(axis.text.x = element_text(angle=65, hjust=1))+
  scale_fill_manual(values = c("right" = "#33CCCC", "is" = "#FF9999"),
                    labels = c("right" = "extreme right attack", "is" = "Islamist attack"))  

 plot_subissue_comp 



#ggsave(filename="FigureC2.Validation_Resonance_sub-issues.jpeg", plot=plot_subissue_comp, device="jpeg", units="cm", width=20, height=13, dpi=300)
 

 

```




```{r subissues before attacks}



#is
issuegroups_before_is <- is_before%>% dplyr::count(subissue_group_eng) %>%
  filter(!is.na(subissue_group_eng)) %>%
 mutate(perc_is=round((n/sum(n)*100),2))

issuegroups_before_is%>% 
kbl(caption="Issue Groups:before Islamist attacks") %>%
  kable_styling()

# right 

issuegroups_before_right <- right_before%>% dplyr::count(subissue_group_eng) %>%
  filter(!is.na(subissue_group_eng)) %>%
 mutate(perc_right=round((n/sum(n)*100),2))

issuegroups_before_right%>% 
kbl(caption="Issue Groups: before Right-wing attacks") %>%
  kable_styling()



issuegroups_before_comp <- full_join(issuegroups_before_right, issuegroups_before_is, by="subissue_group_eng")
#export


#write_xlsx(issuegroups_before_comp, "issuegroups_before_comparison_isright.xlsx")


```





# Legitimacy 

### Table C3: Validation results: Legitimacy shift of actors and issues

**Table 3 Part I: Legitimacy shift of issues***

```{r legitimacy issues}

 # mean position before and after events
#quality issues = position variable on issue level

##is

#before
legitim_is_bef <- is_before %>%
  dplyr:: group_by(issue_string_eng)%>% 
    filter(cs_type_id==1)%>%
  filter(!is.na(issue_string_eng))%>% filter(!is.na(quality_issues))%>%  dplyr::summarize(before_is=mean(quality_issues))


 #after
 
 legitim_is <- is_week1 %>%
 dplyr:: group_by(issue_string_eng)%>% 
    filter(cs_type_id==1)%>%
  filter(!is.na(issue_string_eng))%>% filter(!is.na(quality_issues))%>%  dplyr::summarize(after_is=mean(quality_issues))


 ## right
 
 #before
legitim_right_bef <-  right_before %>%
  dplyr:: group_by(issue_string_eng)%>% 
    filter(cs_type_id==1)%>%
  filter(!is.na(issue_string_eng))%>% filter(!is.na(quality_issues))%>%  dplyr::summarize(before_right=mean(quality_issues))

  
 #after
legitim_right <-right_1week %>%
 dplyr:: group_by(issue_string_eng)%>% 
    filter(cs_type_id==1)%>%
  filter(!is.na(issue_string_eng))%>% filter(!is.na(quality_issues))%>%  dplyr::summarize(after_right=mean(quality_issues))


## merge legitimacy before and after attacks 

legitim_shift_right <- left_join(legitim_right_bef, legitim_right, by="issue_string_eng")

legitim_shift_is <- left_join(legitim_is_bef, legitim_is, by="issue_string_eng")


## calculate shifts (after-before average position)

legitim_shift_is <-legitim_shift_is %>% dplyr::mutate(shift_is=after_is-before_is)

legitim_shift_right <- legitim_shift_right %>% dplyr::mutate(shift_right=after_right-before_right)


#final table: merge legitimacy shifts after Islamist and right attacks

legitim_shift <- left_join(legitim_shift_is,legitim_shift_right,by="issue_string_eng")


#export excel
#write_xlsx(legitim_shift, "legitimacy_shift_issues_isright.xlsx")



legitim_shift %>%
  kbl(caption="Legitimacy shift issues after Islamist and extreme right attacks") %>%
  kable_styling()


```


**Table 3 Part 2: Legitimacy shift of actors**

```{r legitimacy actors}


 # mean position before and after events
#quality id = position variable on actor level
#filter only a-a-sentences - filter(cs_type_id==2)%>%
#is

#before
legitim_actor_is_bef<- is_before %>%
  dplyr:: group_by(object1_eng)%>% 
    filter(cs_type_id==2)%>%
  filter(!is.na(object1_eng))%>% filter(!is.na(quality_id))%>%  dplyr::summarize(before_is=mean(quality_id))

#after
 
 legitim_actor_is <- is_week1 %>%
  dplyr:: group_by(object1_eng)%>% 
    filter(cs_type_id==2)%>%
  filter(!is.na(object1_eng))%>% filter(!is.na(quality_id))%>%  dplyr::summarize(after_is=mean(quality_id))

 
 ## right
 
 #before
 legitim_actor_right_bef <- right_before %>%
  dplyr:: group_by(object1_eng)%>% 
    filter(cs_type_id==2)%>%
  filter(!is.na(object1_eng))%>% filter(!is.na(quality_id))%>%  dplyr::summarize(before_right=mean(quality_id))
  
  #after
 
legitim_actor_right <- right_1week %>%
 filter(!is.na(context_string))%>%
  dplyr:: group_by(object1_eng)%>% 
    filter(cs_type_id==2)%>%
  filter(!is.na(object1_eng))%>% filter(!is.na(quality_id))%>%  dplyr::summarize(after_right=mean(quality_id))

   
## merge legitimacy before and after attacks 

legitim_actor_shift_right <- full_join(legitim_actor_right_bef, legitim_actor_right, by="object1_eng")

legitim_actor_shift_is <- full_join(legitim_actor_is_bef, legitim_actor_is, by="object1_eng")


## calculate shifts (after-before average position)

legitim_actor_shift_is <-legitim_actor_shift_is %>% dplyr::mutate(shift_is=after_is-before_is)

legitim_actor_shift_right <- legitim_actor_shift_right %>% dplyr::mutate(shift_right=after_right-before_right)


#final table: merge legitimacy shifts after Islamist and right attacks

legitim_actor_shift <- full_join(legitim_actor_shift_is,legitim_actor_shift_right,by="object1_eng")


#write_xlsx(legitim_actor_shift, "legitim_actor_shift.xlsx")

legitim_actor_shift %>%
  kbl(caption="Legitimacy shift actors after Islamist and extreme right attacks") %>%
  kable_styling()

```




